<?php
class aluPackTask extends sfBaseTask
{

  protected function configure()
  {
    $this->namespace = 'alu';
    $this->name      = 'pack';
    $this->addArgument('version', sfCommandArgument::REQUIRED, 'version à packager');
    $this->addOption('trunk', null, sfCommandOption::PARAMETER_NONE, 'checkouter le trunk');
  }
  protected function execute($arguments = array(), $options = array())
  {
    $base_url = 'http://ads-log-users.googlecode.com/svn/';
    if ($options['trunk'])
    {
      $svn_url = sprintf('%strunk/', $base_url);
    }
    else
    {
      $svn_url = sprintf('%sbranches/%s/', $base_url, $arguments['version']);
    }

    $cmd = sprintf('svn checkout %s ./tmp/', $svn_url);
    $this->getFilesystem()->execute($cmd);

    $fichiers = sfFinder::type('files')
                  ->ignore_version_control()
                  ->prune('cache')
                  ->prune('.settings')
                  ->prune('log')
                  ->not_name('.project')
                  //todo ajouter dossier test
                  ->not_name('*_dev.php') //TODO ajouter web
                  ->in('tmp/');
                  var_dump(count($fichiers));
    $fichiers = array_map(create_function('$a', sprintf('return substr($a, %s);', strlen(realpath('tmp/'))+1)), $fichiers);
    file_put_contents('tmp/listeFichiers', implode("\n", $fichiers));
    $oldwd = getcwd();
    chdir('tmp/');
    $cmd = sprintf('tar -cf ../adslogusers-%s.tar --files-from=listeFichiers ', $arguments['version']);
    $this->getFilesystem()->execute($cmd);
    $this->getFilesystem()->execute('rm -rf tmp/');

  }
}
